package com.ruoyi.animalManagement.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.animalManagement.domain.LmisQuaItem;
import com.ruoyi.animalManagement.service.ILmisQuaItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * 检疫项目Controller
 * 
 * @author wj
 * @date 2025-08-18
 */
@RestController
@RequestMapping("/animalManagement/quaItem")
public class LmisQuaItemController extends BaseController
{
    @Autowired
    private ILmisQuaItemService lmisQuaItemService;

    /**
     * 查询检疫项目列表
     */
    @PreAuthorize("@ss.hasPermi('animalManagement:quaItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(LmisQuaItem lmisQuaItem)
    {
        startPage();
        List<LmisQuaItem> list = lmisQuaItemService.selectLmisQuaItemList(lmisQuaItem);
        return getDataTable(list);
    }

    /**
     * 导出检疫项目列表
     */
    @PreAuthorize("@ss.hasPermi('animalManagement:quaItem:export')")
    @Log(title = "检疫项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LmisQuaItem lmisQuaItem)
    {
        List<LmisQuaItem> list = lmisQuaItemService.selectLmisQuaItemList(lmisQuaItem);
        ExcelUtil<LmisQuaItem> util = new ExcelUtil<LmisQuaItem>(LmisQuaItem.class);
        util.exportExcel(response, list, "检疫项目数据");
    }

    /**
     * 获取检疫项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('animalManagement:quaItem:query')")
    @GetMapping(value = "/{quaItemId}")
    public AjaxResult getInfo(@PathVariable("quaItemId") Long quaItemId)
    {
        return success(lmisQuaItemService.selectLmisQuaItemByQuaItemId(quaItemId));
    }

    /**
     * 新增检疫项目
     */
    @PreAuthorize("@ss.hasPermi('animalManagement:quaItem:add')")
    @Log(title = "检疫项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LmisQuaItem lmisQuaItem)
    {
        return toAjax(lmisQuaItemService.insertLmisQuaItem(lmisQuaItem));
    }

    /**
     * 修改检疫项目
     */
    @PreAuthorize("@ss.hasPermi('animalManagement:quaItem:edit')")
    @Log(title = "检疫项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LmisQuaItem lmisQuaItem)
    {
        return toAjax(lmisQuaItemService.updateLmisQuaItem(lmisQuaItem));
    }

    /**
     * 删除检疫项目
     */
    @PreAuthorize("@ss.hasPermi('animalManagement:quaItem:remove')")
    @Log(title = "检疫项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{quaItemIds}")
    public AjaxResult remove(@PathVariable Long[] quaItemIds)
    {
        return toAjax(lmisQuaItemService.deleteLmisQuaItemByQuaItemIds(quaItemIds));
    }

    /**
     * 按检疫类型获取检疫项目列表
     */
    @PreAuthorize("@ss.hasPermi('animalManagement:quaItem:list')")
    @GetMapping("/type/{quaType}")
    public AjaxResult listByType(@PathVariable("quaType") int quaType)
    {
        LmisQuaItem query = new LmisQuaItem();
        query.setQuaType(String.valueOf(quaType));
        List<LmisQuaItem> list = lmisQuaItemService.selectLmisQuaItemList(query);
        return success(list);
    }
}
